package com.mui.core
{
	import com.mui.display.*;
	
	import flash.display.*;
	import flash.geom.*;
	import flash.utils.*;
	
	public class GlobalClass extends Object
	{
		public static var libaray:Library = new Library("global");
		private static var _bitmapdataMap:Dictionary = new Dictionary();
		
		public function GlobalClass()
		{
		}
		
		public static function getInstance(param1:String) : *
		{
			var className:Class = libaray.getDefinition(param1);
			return new className;
		}
		
		public static function getClass(classname:String) : Class
		{
			return libaray.getDefinition(classname);
		}
		
		public static function getBitmapData(key:String) : BitmapData
		{
			if (!(key in _bitmapdataMap))
			{
				_bitmapdataMap[key] = getBitmapdataImpl(key);
			}
			return _bitmapdataMap[key];
		}
		
		public static function getBitmap(key:String) : Bitmap
		{
			var bitmapData:BitmapData = getBitmapData(key);
			if (bitmapData != null)
			{
				return new Bitmap(bitmapData);
			}
			return null;
		}
		
		public static function getScaleBitmap(key:String, r:Rectangle = null) : ScaleBitmap
		{
			var scaleBitmap:ScaleBitmap = null;
			var bitmapData:BitmapData = getBitmapData(key);
			if (bitmapData != null)
			{
				scaleBitmap = new ScaleBitmap(bitmapData.clone());
				scaleBitmap.scale9Grid = r;
				return scaleBitmap;
			}
			return null;
		}
		
		private static function getBitmapdataImpl(classname:String) : BitmapData
		{
			var iclass:Class = getClass(classname);
			if (iclass != null)
			{
				return new iclass(0, 0) as BitmapData;
			}
			return null;
		}
	}
}
